package com.example.back.controller;

import com.example.back.dao.GroupDao;
import com.example.back.http.HttpCreate;
import com.example.back.util.SendUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.http.HttpEntity;
import org.apache.http.ParseException;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

@Api(tags = "创建俱乐部以及充值金币接口")
@RestController
@RequestMapping("/http")
public class HttpController {

    @Autowired
    private SendUtil sendUtil;

    @Autowired
    private GroupDao groupDao;

    @ApiOperation(value = "增加金币接口",notes = "已废弃",httpMethod = "POST")
    @RequestMapping("/addCoin")
    public String add(int num,int userId)  {
        HttpCreate httpCreate = new HttpCreate();
        String uri = "http://119.91.143.179:8080/guajiLogin/groupActionNew!addCard.guajilogin?freeCard="+num+"&mysign=myniubi147&userId="+userId;
        //        System.out.println(http);
        return httpCreate.http(uri);
    }

    @ApiOperation(value = "创建俱乐部接口",notes = "已废弃",httpMethod = "POST")
    @RequestMapping("/create")
    public String create(String num,int userId)  {
        HttpCreate httpCreate = new HttpCreate();
        String uri = "http://119.91.143.179:8080/guajiLogin/groupActionNew!createGroup.guajilogin?groupName="+num+"&mysign=myniubi258&userId="+userId;
        //        System.out.println(http);
        return httpCreate.http(uri);
    }

    @RequestMapping("/checkpoint")
    public String checkpoint(String num,int userId)  {
        groupDao.updateLevel(Integer.parseInt(num),(long)userId);
        System.out.println("更新玩家关卡");
        Map<String,String> map = new HashMap();
        map.put("type",18+"");
        map.put("IUserId",userId+"");
        map.put("level",num);
        String send = sendUtil.send(1, map);

        return send;
    }

    public static void main(String[] args) {
        HttpController httpController = new HttpController();
        httpController.add(10000,120004);
    }


}
